import { User_Login,Reset_User,User_Login_Error, Update_User_Info } from './action_type'
export function user(state = {}, action) {
    switch (action.type) {
        case User_Login:
            return { ...state, userInfo: action.data, errmsg: null }
        case User_Login_Error:
            return { ...state, userInfo: null, errmsg: action.data }
        case "Update_User_Info":
            return {...state, userInfo: action.data,errmsg: null}
        case Reset_User:
            return {userInfo: null}
        default :
            return state
    }
}

// 聊天界面用到的
// 与我有关的消息   和 用户信息的对象
export function chat(state = { chatMsg:[],users: {} ,unReadCount: 0},action){
    switch (action.type) {
        case "Receive_OneMsg":
            let {userid} = action.data
            let newMsg = action.data.chatMsg
            return {...state, chatMsg: [...state.chatMsg,newMsg], unReadCount: !newMsg.read && newMsg.to === userid ? state.unReadCount + 1 : state.unReadCount }
        case "Receive_Msg_List":        //获取消息列表
            let {users={}, chatMsg=[], unReadCount} = action.data;
            return { users, chatMsg, unReadCount}
        default:
            return state;
    }
}